﻿<Window x:Class="DrawingIn3D.CubeMesh"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CubeMesh" Height="331.2" Width="361.6"
        xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"
    >
  <Window.Resources>
    <MeshGeometry3D x:Key="SharedPoints"  Positions="0,0,0 10,0,0 0,10,0 10,10,0
                                           0,0,10 10,0,10 0,10,10 10,10,10"
                       TriangleIndices="0,2,1 1,2,3 0,4,2 2,4,6 
                                                 0,1,4 1,5,4 1,7,5 1,3,7 
                                                 4,5,6 7,6,5 2,6,3 3,6,7"
                        />
    <MeshGeometry3D x:Key="Blended"  Positions="0,0,0 10,0,0 0,10,0 10,10,0
                                           0,0,10 10,0,10 0,10,10 10,10,10"
                        TriangleIndices="0,2,1 1,2,3 0,4,2 2,4,6 
                                                 0,1,4 1,5,4 1,7,5 1,3,7 
                                                 4,5,6 7,6,5 2,6,3 3,6,7"
                         Normals="0,1,0 0,1,0 1,0,0 1,0,0
                                 0,1,0 0,1,0 1,0,0 1,0,0" />
    <MeshGeometry3D x:Key="Faceted"
                 Positions="0,0,0 10,0,0 0,10,0 10,10,0
                             0,0,0 0,0,10 0,10,0 0,10,10
                             0,0,0 10,0,0 0,0,10 10,0,10
                             10,0,0 10,10,10 10,0,10 10,10,0
                             0,0,10 10,0,10 0,10,10 10,10,10
                             0,10,0 0,10,10 10,10,0 10,10,10"
                 TriangleIndices="0,2,1 1,2,3
                                   4,5,6 6,5,7                                   
                                   8,9,10 9,11,10                                   
                                   12,13,14 12,15,13
                                   16,17,18 19,18,17
                                   20,21,22 22,21,23" />
  </Window.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <Border BorderBrush="Yellow" BorderThickness="1" Margin="5">
      <Viewport3D>
        <Viewport3D.Camera>
          <PerspectiveCamera
          FarPlaneDistance="100"
          LookDirection="2,-1,-1"
          UpDirection="0,1,0"
          NearPlaneDistance="1"
          Position="-20,15,15"
          FieldOfView="60"
            >

          </PerspectiveCamera>
        </Viewport3D.Camera>
        <ModelVisual3D>
          <ModelVisual3D.Content>
            <DirectionalLight
             Color="White"
             Direction="-2,-3,-1" />
          </ModelVisual3D.Content>
        </ModelVisual3D>

        <ModelVisual3D>
          <ModelVisual3D.Content>
            <DirectionalLight
             Color="White"
             Direction="2,3,1" />
          </ModelVisual3D.Content>

        </ModelVisual3D>

        <ModelVisual3D>
          <ModelVisual3D.Content>
            <GeometryModel3D Geometry="{StaticResource Blended}" x:Name="cubeGeometry">              
              <GeometryModel3D.Material>
                <DiffuseMaterial Brush="LightBlue" />
              </GeometryModel3D.Material>
            </GeometryModel3D>
          </ModelVisual3D.Content>
          <ModelVisual3D.Transform>
            <RotateTransform3D>
              <RotateTransform3D.Rotation>
                <AxisAngleRotation3D x:Name="rotate"
                                     Axis="0 1 0" />
              </RotateTransform3D.Rotation>
            </RotateTransform3D>
          </ModelVisual3D.Transform>
        </ModelVisual3D>

       <tools:ScreenSpaceLines3D Points="0,-20,0 0,20,0"
          Thickness="1" Color="Red">
        </tools:ScreenSpaceLines3D>
        <tools:ScreenSpaceLines3D Points="-20,0,0 20,0,0"
          Thickness="1" Color="Red">
        </tools:ScreenSpaceLines3D>
        <tools:ScreenSpaceLines3D Points="0,0,-20 0,0,20"
          Thickness="1" Color="Red">
        </tools:ScreenSpaceLines3D>
      </Viewport3D>
    </Border>

    <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
      <StackPanel.Resources>
        <Style TargetType="{x:Type Button}">
          <Setter Property="Margin" Value="3"/>
          <Setter Property="Padding" Value="3"/>
          <EventSetter Event="Click" Handler="cmd_Click" />
        </Style>
      </StackPanel.Resources>
      <Button Tag="{StaticResource SharedPoints}">Shared Points</Button>
      <Button Tag="{StaticResource Faceted}">Faceted</Button>
      <Button Tag="{StaticResource Blended}">Blended</Button>
    </StackPanel>
    <ScrollBar Grid.Row="2"  Minimum="0" Maximum="360" Orientation="Horizontal"
              Value="{Binding ElementName=rotate, Path=Angle}" ></ScrollBar>

  </Grid>
</Window>
